<template>
  <div id="container">
    <div id="swiper">
      <van-swipe
          class="my-swipe"
          ref="swipe"
          @change="onChange"
          autoplay="3000"
          width="360px"
      >
        <van-swipe-item>1</van-swipe-item>
        <van-swipe-item>2</van-swipe-item>
        <van-swipe-item>3</van-swipe-item>
        <van-swipe-item>4</van-swipe-item>
      </van-swipe>
    </div>
    <div id="toLabel">
      <div>
        <img style="width: 50px" :src="allSongSrc" alt="">
        <span>歌曲库</span>
      </div>
      <div>
        <img style="width: 50px" :src="allSingerSrc" alt="">
        <span>热门歌手</span>
      </div>
      <div>
        <img style="width: 50px" :src="songTypeSrc" alt="">
        <span>歌曲分类</span>
      </div>
      <div>
        <img style="width: 50px" :src="newSongSrc" alt="">
        <span>精选歌单</span>
      </div>
    </div>
    <div id="hot">
      <span style="font-size: 16px;font-weight: bold">强烈为你挑选  ></span>
      <!--   换一批   -->
      <img @click="changeSelectSong" :src="changeHotSongSrc" alt="">
      <div class="hotDetail">
        <div class="sonHotDetail" v-for="(item,index) of selectSongs" :key="index" @click="hotSelectToPlayer(item)">
          <img style="max-width: 100px;max-height: 100px" :src="item.photo" alt="">
          <span style="font-size: 13px;"> {{item.name}}</span>
        </div>
      </div>
    </div>
    <!--  歌单里回忆的歌  -->
    <div id="memory">
      <span style="font-size: 16px;font-weight: bold">那些年回忆的歌    ></span>
    </div>
    <div id="new">
      <span style="font-size: 16px;font-weight: bold">新歌首发    ></span>
    </div>
  </div>
</template>

<script>
import request from "../../utils/request";

export default {
  name: "Square",
  data() {
    return {
      allSongSrc: require('../../assets/allSong.png'),
      allSingerSrc: require('../../assets/allSinger.png'),
      songTypeSrc: require('../../assets/songType.png'),
      newSongSrc: require('../../assets/newSong.png'),
      changeHotSongSrc: require('../../assets/changHotSong.png'),
      selectSongs: []
    }
  },
  methods: {
    onChange(index) {
      // console.log('当前 Swipe 索引：' + index+1);
    },
    //强烈为你挑选
    getRandomSelectSong(count) {
      request.request({
        method: 'get',
        url: '/api/song/getSong'
      }).then(res => {
        if (res.data.code == '200') {
          var shuffled = res.data.data.slice(0), i = res.data.data.length, min = i - count, temp, index;
          while (i-- > min) {
            index = Math.floor((i + 1) * Math.random());
            temp = shuffled[index];
            shuffled[index] = shuffled[i];
            shuffled[i] = temp;
          }
          this.selectSongs = shuffled.slice(min);
        }
      })
    },
    changeSelectSong() {
      this.getRandomSelectSong(6)
    },
    hotSelectToPlayer(item){
      this.$router.push('/player')
      this.$bus.$emit('showNav',false)
      this.$bus.$emit('setPlayerSongId',item.songId)
    }
  },
  mounted() {
    setTimeout(() => {
      this.$refs.swipe.resize()
    }, 500)
    this.getRandomSelectSong(6)
  }
}
</script>

<style scoped>
#container {
  width: 100%;
}

#container > div {
  width: 96%;
  margin-left: 2%;
  margin-top: 20px;
}

#swiper {
  height: 200px;
  border: 1px solid #c0c0c0;
}

#toLabel {
  display: flex;
  height: 100px;
  border: 1px solid green;
  justify-content: space-around;
  align-items: center;
}

#toLabel > div {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

#toLabel > div > span {
  font-size: 14px;
  margin-top: 5px;
}

#hot {
  position: relative;
  height: 250px;
  border: 1px solid #faa726;
}

#hot > img {
  position: absolute;
  width: 24px;
  right: 5px;
}

.hotDetail {
  width: 100%;
  height: 220px;
  margin-top: 10px;
  border: 1px solid blue;
  display: flex;
  flex-wrap: wrap;
  flex: 1;
  justify-content: center;
  align-items: center;
}

.sonHotDetail {
  border-radius: 5%;
  min-width: 120px;
  height: 100px;
  overflow: hidden;
  border: 1px solid #ee00ff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

#memory {
  height: 250px;
  border: 1px solid #4af83e;
}

#new {
  height: 250px;
  border: 1px solid #f83e3e;
}

.my-swipe .van-swipe-item {
  width: 100%;
  height: 200px;
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  background-color: #39a9ed;
}
</style>